package com.xm.xmds1705083.web.controller;

import com.xm.xm.dto.ResultDto;
import com.xm.xm.dto.SearchDto;
import com.xm.xmds1705083.service.service.DuoduoUserCarService;
import com.xm.xmds1705083.web.base.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 杭州新苗网络科技有限公司
 *
 * @author meihf
 * @create 2017/6/15
 * @description
 */
@Controller
@RequestMapping("userCar")
public class UserCarController extends BaseController{

    @Autowired
    DuoduoUserCarService duoduoUserCarService;

    /**
     * 获取我的车辆
     */
    @RequestMapping("/findMyMediaNo")
    @ResponseBody
    public ResultDto findMyMediaNo(@RequestBody SearchDto searchDto){
        searchDto.setAppUserId(getUserId());
        return duoduoUserCarService.findMyMediaNo(searchDto);
    }


    /**
     * 添加车辆
     */
    @RequestMapping("/saveMyMediaNo")
    @ResponseBody
    public ResultDto saveMyMediaNo(@RequestBody SearchDto searchDto){
        searchDto.setAppUserId(getUserId());
        return duoduoUserCarService.saveMyMediaNo(searchDto);
    }

    /**
     * 删除我的车辆
     */
    @RequestMapping("/deleteMyMediaNo")
    @ResponseBody
    public ResultDto deleteMyMediaNo(@RequestBody SearchDto searchDto){
        searchDto.setAppUserId(getUserId());
        return duoduoUserCarService.deleteMyMediaNo(searchDto);
    }

    /**
     * 认证我的车牌
     */
    @RequestMapping("/certfMyMediaNo")
    @ResponseBody
    public ResultDto certfMyMediaNo(@RequestBody SearchDto searchDto) {
        /*searchDto.setAppUserId(getUserId());*/
        String authorization =   getRequest().getHeader("AUTHORIZATION");
        if (authorization!=null){
            searchDto.setAppUserId(Math.abs( Long.valueOf( authorization.split("\\_")[0] ) ));
        }
        return duoduoUserCarService.certfMyMediaNo(searchDto);
    }

    /**
     * 认证我的车位是否发布
     */
    @RequestMapping("/certfIssueMyMediaNo")
    @ResponseBody
    public ResultDto certfIssueMyMediaNo(@RequestBody SearchDto searchDto) {
        searchDto.setAppUserId(getUserId());
        return duoduoUserCarService.certfIssueMyMediaNo(searchDto);
    }

}
